# vim:ts=8 sw=4 noet:
#

PDFLATEX = pdflatex
NOTANGLE = notangle
NOWEAVE  = noweave

# -- high-level targets
.PHONY:	    all doc clean pdf test

all:	    badges doc test

doc:	    badges.pdf

clean:
	    rm -f *.log *.aux *.inc *.tex *.out *.toc
	    
clobber:    clean
	    rm -f badges.ps .ps badges.pdf
	    rm -f example.pdf example.ps
	    rm -f test.*
	    rm -f debug.*
	    rm -f badges

dist:	    badges badges.pdf 
	    rsync badges badges.pdf vistabella.de:/var/www/badges

# -- rules

example.ps: badges.nw
	    $(NOTANGLE) -Rexample.ps $< > $@

sample.ps:  badges.nw
	    $(NOTANGLE) -Rsample.ps $< > $@

debug.ps:   badges.nw
	    $(NOTANGLE) -Rdebug.ps $< > $@



badges:	    badges.nw
	    $(NOTANGLE) -Rbadges.rb $< > $@
	    chmod +x $@

libbadges.ps:  badges.nw
	    $(NOTANGLE) -Rbadges.ps $< > $@

%.pdf:	    %.ps
	    gs -sDEVICE=pdfwrite -dBATCH -sOutputFile=$@ -dNOPAUSE $<

%.pdf:	    %.eps
	    gs -sDEVICE=pdfwrite -dBATCH -sOutputFile=$@ -dNOPAUSE $<

# -- documentation

RERUN =     Rerun (LaTeX|to get cross-references right)

pdf:	    $(PDF)

%.pdf:	%.tex 
	    $(PDFLATEX) $<
	    if egrep -s '$(RERUN)' $*.log ;then $(PDFLATEX) $<; fi
	    if egrep -s '$(RERUN)' $*.log ;then $(PDFLATEX) $<; fi

%.tex:      %.nw
	    $(NOWEAVE) -delay $< > $@

# -- Tests

.PHONY:	    test

test:	    test.ps test.pdf test12.ps test12.pdf

RR =	    "Ronald Rivest::Massachusetts Institute^of Technology::rr::abcd" 
OPTS=	    -o 0,-1,0,1 -s "Frontiers of^Electronic Voting" -d 1234 -x \
	    -i "this space is for rent" -n 07000 -D ManualFeed:true

test.ps:    badges Makefile
	    echo $(RR) | ./badges $(OPTS) -m -c 4 > $@

test12.ps:  badges Makefile
	    echo $(RR) | ./badges $(OPTS) -m -b white -c 10 > $@


